package com.epigeon.amadeo.impl;

import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;

import com.epigeon.amadeo.engine.Engine;
import com.epigeon.amadeo.input.ActiveInput;
import com.epigeon.amadeo.input.PassiveInput;
import com.epigeon.amadeo.model.Message;

public abstract class ActiveButton extends Button implements ActiveInput {

	private List<PassiveInput> passiveInputs = new LinkedList<PassiveInput>();
	private Message message = null;
	private String key = null;
	
	public ActiveButton(Context context, AttributeSet attr) {
		super(context, attr);
		
		this.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				update();
			}
		});
	
	}

	@Override
	public void addPassiveInput(PassiveInput passiveInput) {
		passiveInputs.add(passiveInput);
	}

	@Override
	public Message getMessage() {
		return message;
	}
			
	public void update() {
		List<Message> messageList = new LinkedList<Message>();
		for (PassiveInput passiveInput : passiveInputs) {
			messageList.add(passiveInput.getMessage());					
		}
		message = compose(messageList);

		Engine.getInstance().activeInputNotification(this, this.message);
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}
}